#include <mutex>
#include "SL_asynFrameImp.h"
#include "SL_asynFrame.h"
#include "SL_asynFramePub.h"
#include "SLT_log.h"

static std::mutex SLF_frameImpLock_20220124;
static SLF_frameImp* g_pdefFrame_20220124 = nullptr;
SLT_API uint32_t SLF_init(int _threadNum)
{
	int ret = 0;
	if (g_pdefFrame_20220124 == nullptr) {
		SLF_frameImpLock_20220124.lock();
		printf("%s\n", __sl_base_version__);
		SLT_LOG_ERR("%s", __sl_base_version__);
		if (g_pdefFrame_20220124 == nullptr) {
			g_pdefFrame_20220124 = new SLF_frameImp();
			ret = g_pdefFrame_20220124->SLF_init(_threadNum);
		}
		SLF_frameImpLock_20220124.unlock();
	}
	return ret;
}
SLT_API uint32_t SLF_start()
{
	return g_pdefFrame_20220124->SLF_start();
}
bool SLF_addSession(const SLF_SessionBasePtr &_psession)
{
	return g_pdefFrame_20220124->SLF_addSession(_psession);
}
void SLF_delSession(uint32_t _sessId)
{
	g_pdefFrame_20220124->SLF_delSession(_sessId);
}
bool SLF_postMsg(uint32_t _SessID, int _msgid, uint32_t _srcID, const SLF_sendMemBasePtr &_data)
{
	return g_pdefFrame_20220124->SLF_postMsg(_SessID, _msgid, _srcID,_data);
}
bool SLF_postMsg2(uint32_t _SessID, int _msgid, uint32_t _srcID, SLF_sendMemBasePtr &_data, const SLF_senderPtr &_senderPtr)
{
	return g_pdefFrame_20220124->SLF_postMsg2(_SessID, _msgid, _srcID, _data, _senderPtr);
}
SLT_API bool SLF_postMsg3(uint32_t _SessID, int _msgid, uint32_t _srcID, const char* _data, int _dataLen, const SLF_senderPtr& _senderPtr)
{
	//SLF_sendMemBasePtr sendmem = std::make_shared< SLF_sendMemBase>();
	SLF_sendMemBasePtr sendmem(new SLF_sendMemBase());
	sendmem->add((char*)_data, _dataLen);
	return g_pdefFrame_20220124->SLF_postMsg2(_SessID, _msgid, _srcID, sendmem, _senderPtr);
}
bool SLF_pushEvent(uint32_t _SessID, int _msgid, uint32_t _srcID, SLF_sendMemBasePtr _data, const SLF_senderPtr & _senderPtr)
{
	return g_pdefFrame_20220124->SLF_pushEvent(_SessID, _msgid, _srcID, _data, _senderPtr);
}
/////////////////////////////////////////////////////////////////////////
SLF_frame* SLF_CreateFrame()
{
	return new SLF_frameImp();
}
/////////////////////////////////////////////////////////////////////////
